package pattern.creational.singleton;

/**
 * 利用jvm初始化对象时候的初始化锁
 * jvm加载类之后，在线程使用之前都可以叫做是对象的初始化阶段
 *
 * @Author Gavin
 * @date 2020.07.15 15:25
 */
public class StaticInnerSingleton {
    private static class InnerClass {
        private static StaticInnerSingleton instance = new StaticInnerSingleton();
    }

    public static StaticInnerSingleton getInstance() {
        return InnerClass.instance;
    }

    private StaticInnerSingleton() {
        if (InnerClass.instance != null) {
            throw new RuntimeException("单例构造器禁止反射调用。");
        }
    }
}
